package com.gombe.credit.app.base;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.gombe.credit.app.R;
import com.gombe.credit.app.ui.dialog.DialogGombeCreditLoading;
import com.gombe.credit.app.utils.GombeCreditToastManager;
import com.gombe.credit.lib.adapter.GombeCreditOnSingleClickListener;

public abstract class BaseDialog extends Dialog implements IBaseView,View.OnClickListener {

    public BaseDialog(Context context) {
        super(context, R.style.DialogTheme);
    }

    public BaseDialog(Context context, int style) {
        super(context, style);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(takeGombeCreditRootView());
        initGombeCreditWindow();
        initGombeCreditView();
        initGombeCreditListener();
        takeGombeCreditData();
    }

    protected abstract View takeGombeCreditRootView();

    /**
     * 初始化Window
     */
    protected abstract void initGombeCreditWindow();

    /**
     * 初始化布局
     */
    protected abstract void initGombeCreditView();

    /**
     * 初始化监听
     */
    protected abstract void initGombeCreditListener();

    /**
     * 初始化数据
     */
    protected abstract void takeGombeCreditData();

    /**
     * 控件点击事件
     */
    protected abstract void onGombeCreditViewClick(View v);

    @Override
    public void showGombeCreditLoading() {
        DialogGombeCreditLoading.Companion.show(getContext(),false,false,"");
    }

    @Override
    public void hideGombeCreditLoading() {
        DialogGombeCreditLoading.Companion.dismiss(getContext());
    }

    @Override
    public void showGombeCreditToast(String s) {
        GombeCreditToastManager.showShortText(getContext(), s);
    }

    @Override
    public void onClick(View v) {
        onGombeCreditViewClick(v);
    }

    protected void setOnClickListener(View view) {
        view.setOnClickListener(new GombeCreditOnSingleClickListener() {
            @Override
            public void onSingleClick(View v) {
                onGombeCreditViewClick(v);
            }
        });
    }
}
